//
//  UISwitch+RAC.m
//  高仿暴走斗图
//
//  Created by huangsongyao on 16/3/27.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "UISwitch+RAC.h"

#ifdef __IPHONE_8_0
// suppress these errors until we are ready to handle them
#pragma clang diagnostic ignored "-Wobjc-designated-initializers"

#else
// temporarily define an empty NS_DESIGNATED_INITIALIZER so we can use now,
// will be ready for iOS8 SDK
#define NS_DESIGNATED_INITIALIZER

#endif

@implementation UISwitch (RAC)

#pragma mark - Create Switch

+ (UISwitch *)rac_createSwitchWithIsOpen:(BOOL)isOpen selectCompletion:(void(^)(id x))completion {
    
    return [[self alloc] initWithRAC_createSwitchWithIsOpen:isOpen selectCompletion:completion];
}

- (UISwitch *)initWithRAC_createSwitchWithIsOpen:(BOOL)isOpen selectCompletion:(void(^)(id x))completion {
    
    if (self = [super init]) {
        
        self.on = isOpen;
        [[[self rac_newOnChannel] deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(id x) {
            if (completion) {
                completion(x);
            }
        }];
    }
    return self;
}

@end
